﻿<UserControl x:Class="CodeBuilder2.View.CB_UserControl.Content.DataBaseContent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="192">
    <UserControl.Resources>
        <!--定义数据库级节点的右键菜单-->
        <ContextMenu x:Key="databaseContextMenu">
            <MenuItem Header="生成 _Model 类..." Click="MenuItem_Click"/>
            <MenuItem Header="生成 _BLL 类..."/>
            <MenuItem Header="生成 _DAL 类..."/>
            <Separator/>
            <MenuItem Header="生成 _Procedure 语句..."/>
            <MenuItem Header="备份数据库..."/>
        </ContextMenu>
        <!--为 TreeViewItem 的 Header 对象设计数据模板，并在模板内指定数据触发器，
        所有 TreeViewItem.Tag 的值等于 3 的节点具有右键菜单对象-->
        <Style TargetType="TreeViewItem">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate DataType="string">
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Name="chkTVI" Margin="0,1,1,0" IsThreeState="True"/>
                            <TextBlock Name="tbkTitle" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TreeViewItem}, Path=Header}"/>
                        </StackPanel>
                        <DataTemplate.Triggers>
                            <!--3代表的是数据库级节点-->
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TreeViewItem}, Path=Tag}" Value="3">
                                <Setter TargetName="tbkTitle" Property="ContextMenu" Value="{StaticResource databaseContextMenu}"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <TreeView  Margin="5" Name="tvInstance">
            <!--<TreeViewItem Header="一级" IsExpanded="True">
                <TreeViewItem Header="一二级" IsExpanded="True">
                    <TreeViewItem.Style>
                        <Style TargetType="TreeViewItem">
                            <Setter Property="Foreground" Value="green"/>
                        </Style>
                    </TreeViewItem.Style>
                    <TreeViewItem Header="一二三级" />
                </TreeViewItem>
                <TreeViewItem Header="二二级"/>
            </TreeViewItem>
            <TreeViewItem IsExpanded="True" Header="一级">                
                <TreeViewItem.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Margin="0,3,3,0"/>
                            <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TreeViewItem}, Path=Header}"/>
                        </StackPanel>
                    </DataTemplate>
                </TreeViewItem.HeaderTemplate>                
                <TreeViewItem Header="一二级" />
                <TreeViewItem Header="一三级" />
            </TreeViewItem>-->
        </TreeView>
    </Grid>
</UserControl>
